package com.syp.auth.export.common;

import java.net.URLEncoder;

public final class GorgeousParameters {

	/**
	 * 登录之后写入的认证token
	 */
	public static final String AUTH_COOKIE_NAME = "X-AUTHENTICATION-TOKEN";
	/**
	 * 登录认证地址
	 */
	public static final String AUTH_SIGNGIN_PATH = "/api/authorize/signin";

	/**
	 * UTF-8编码
	 */
	public static final String CHARSET_UTF8 = "UTF-8";

	/**
	 * 会话ID统一前缀
	 */
	public static final String SESSION_ID_PREFIX = "COMMON.ERP:SID:";

	/**
	 * 图片验证码统一前缀
	 */
	public static final String IVC_PREFIX = "COMMON.ERP:IVC:";

	/**
	 * 短信验证码统一前缀
	 */
	public static final String SMSVC_PREFIX = "COMMON.ERP:SMSVC:";

	/**
	 * 图片验证码宽度
	 */
	public static final int IVC_WIDTH = 200;

	/**
	 * 图片验证码高度
	 */
	public static final int IVC_HEIGHT = 80;

	/**
	 * token有效小时数
	 */
	public static final int TOKEN_EXISTS_HOURS = 168;

	/**
	 * token有效分钟数
	 */
	public static final int TOKEN_EXISTS_MINUTES = 60;

	/**
	 * 5分钟内访问的URL统一前缀
	 */
	public static final String ACCESS_LOG_PREFIX = "COMMON.ERP:ACCESSLOG:";
	/**
	 * 同一ip统一访问统计员记录日志最大次数
	 */
	public static final long SAME_ACCESS_MAX_LOG_TIMES = 10;
	/**
	 * 同访问日志控制间隔
	 */
	public static final long ACCESS_LOG_CONTROL_MINUTES = 5;

	/**
	 * 登录跳转 uri
	 * @param authBaseUrl
	 * @param returnUrl
	 * @param sid
	 * @param app
	 * @return
	 */
	public static final String buildSigninUri(String authBaseUrl, String returnUrl, String sid, String app) {
		StringBuilder sb = new StringBuilder();
		try {
			sb.append(authBaseUrl == null ? "" : authBaseUrl);
			sb.append(GorgeousParameters.AUTH_SIGNGIN_PATH);
			sb.append("?").append(SigninParamEnum.RETURN_URL.getParam()).append("=");
			sb.append(URLEncoder.encode(returnUrl, GorgeousParameters.CHARSET_UTF8));
			sb.append("&").append(SigninParamEnum.SESSION_ID.getParam()).append("=");
			sb.append(sid);
			sb.append("&").append(SigninParamEnum.APP.getParam()).append("=");
			sb.append(app);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

		return sb.toString();
	}

}
